package com.ruoyi.web.controller.train;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.service.TokenService;
import com.ruoyi.system.domain.PracticeBaseUser;
import com.ruoyi.system.service.IPracticeBaseUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 实践基地对应管理员Controller
 *
 * @author dp
 * @date 2023-11-30
 */
@Api(tags = {"实践基地对应管理员"})
@RestController
@RequestMapping("/practice/user")
public class PracticeBaseUserController extends BaseController {
    @Autowired
    private IPracticeBaseUserService practiceBaseUserService;
    @Autowired
    TokenService tokenService;

    /**
     * 查询实践基地对应管理员列表
     */
    @ApiOperation(value = "实践基地对应管理员列表", notes = "查询实践基地对应管理员列表详情", tags = {"实践基地对应管理员管理"})
    // @PreAuthorize("@ss.hasPermi('system:USER:list')")
    @GetMapping("/list")
    public TableDataInfo list(PracticeBaseUser practiceBaseUser) {
        startPage();
        List<PracticeBaseUser> list = practiceBaseUserService.selectPracticeBaseUserList(practiceBaseUser);
        return getDataTable(list);
    }

    /**
     * 导出实践基地对应管理员列表
     */
    @ApiOperation(value = "实践基地对应管理员列表导出", notes = "导出实践基地对应管理员列表详情", tags = {"实践基地对应管理员管理"})
    //@PreAuthorize("@ss.hasPermi('system:USER:export')")
    @Log(title = "实践基地对应管理员", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PracticeBaseUser practiceBaseUser) {
        List<PracticeBaseUser> list = practiceBaseUserService.selectPracticeBaseUserList(practiceBaseUser);
        ExcelUtil<PracticeBaseUser> util = new ExcelUtil<PracticeBaseUser>(PracticeBaseUser.class);
        util.exportExcel(response, list, "实践基地对应管理员数据");
    }

    /**
     * 获取实践基地对应管理员详细信息
     */
    @ApiOperation(value = "获取实践基地对应管理员详细信息", notes = "获取实践基地对应管理员详细信息详情", tags = {"实践基地对应管理员管理"})
    //@PreAuthorize("@ss.hasPermi('system:USER:query')")
    @GetMapping(value = "/{baseUserId}")
    public AjaxResult getInfo(@PathVariable("baseUserId") Long baseUserId) {
        return success(practiceBaseUserService.selectPracticeBaseUserByBaseUserId(baseUserId));
    }

    /**
     * 新增实践基地对应管理员
     */
    @ApiOperation(value = "新增实践基地对应管理员", notes = "新增实践基地对应管理员详情", tags = {"实践基地对应管理员管理"})
    //@PreAuthorize("@ss.hasPermi('system:USER:add')")
    @Log(title = "实践基地对应管理员", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PracticeBaseUser practiceBaseUser) {
        return toAjax(practiceBaseUserService.insertPracticeBaseUser(practiceBaseUser));
    }

    /**
     * 修改实践基地对应管理员
     */
    @ApiOperation(value = "修改实践基地对应管理员", notes = "修改实践基地对应管理员详情", tags = {"实践基地对应管理员管理"})
    //@PreAuthorize("@ss.hasPermi('system:USER:edit')")
    @Log(title = "实践基地对应管理员", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PracticeBaseUser practiceBaseUser) {
        return toAjax(practiceBaseUserService.updatePracticeBaseUser(practiceBaseUser));
    }

    /**
     * 删除实践基地对应管理员
     */
    @ApiOperation(value = "删除实践基地对应管理员", notes = "删除实践基地对应管理员详情", tags = {"实践基地对应管理员管理"})
    //@PreAuthorize("@ss.hasPermi('system:USER:remove')")
    @Log(title = "实践基地对应管理员", businessType = BusinessType.DELETE)
    @DeleteMapping("/{baseUserIds}")
    public AjaxResult remove(@PathVariable Long[] baseUserIds) {
        return toAjax(practiceBaseUserService.deletePracticeBaseUserByBaseUserIds(baseUserIds));
    }

    /**
     * 批量新增临床实践基地对应管理员
     */
    @ApiOperation(value = "批量新增临床实践基地对应管理员", notes = "批量新增临床实践基地对应管理员详情", tags = {"临床实践基地对应管理员管理"})
    //@PreAuthorize("@ss.hasPermi('system:role:edit')")
    @Log(title = "批量新增临床实践基地对应管理员", businessType = BusinessType.GRANT)
    @PutMapping("/authUser")
    public AjaxResult selectAuthUserAll(Long baseId, Long[] userIds) {
        return toAjax(practiceBaseUserService.insertAuthUsers(baseId, userIds));
    }

}
